<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ccut" uri="http://ccut.cn/common/"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="">
	<meta name="author" content="">

	<title>订单列表</title>

	<!-- Bootstrap Core CSS -->
	<link href="${pageContext.request.contextPath}/mb/css/bootstrap.min.css" rel="stylesheet">

	<!-- MetisMenu CSS -->
	<link href="${pageContext.request.contextPath}/mb/css/metisMenu.min.css" rel="stylesheet">

	<!-- DataTables CSS -->
	<link href="${pageContext.request.contextPath}/mb/css/dataTables.bootstrap.css" rel="stylesheet">

	<!-- Custom CSS -->
	<link href="${pageContext.request.contextPath}/mb/css/sb-admin-2.css" rel="stylesheet">

	<!-- Custom Fonts -->
	<link href="${pageContext.request.contextPath}/mb/css/font-awesome.min.css" rel="stylesheet"
		  type="text/css">
	<link href="${pageContext.request.contextPath}/mb/css/boot-crm.css" rel="stylesheet"
		  type="text/css">

	<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
	<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->

</head>

<body>

<div class="panel panel-default">
	<div class="panel-body">
		<form class="form-inline" action="${pageContext.request.contextPath }/order/list" method="post">
			<div class="form-group">
				<label for="order_name">订单名称</label>
				<input type="text" class="form-control" id="order_name" value="" name="order_name">
			</div>
			<div class="form-group">
				<label for="order_uname">订单人</label>
				<input type="text" class="form-control" id="order_uname" name="order_uname">
			</div>
			<div class="form-group">
				<label for="order_state">订单状态</label>
				<select	class="form-control" id="order_state" placeholder="订单来源" name="order_state">
					<option value="">--请选择--</option>
						<option value="0">未完成</option>
						<option value="1">已完成</option>
				</select>
			</div>
			<button type="submit" class="btn btn-primary">查询</button> &nbsp; &nbsp;&nbsp;
		</form>
	</div>
</div>
<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<!-- /.panel-heading -->
			<table class="table table-bordered table-striped">
				<thead>
				<tr>
					<th>ID</th>
					<th>订单名称</th>
					<th>订单金额</th>
					<th>订单时间</th>
					<th>订单人</th>
					<th>订单状态</th>
					<th width="120:px">操作</th>

				</tr>
				</thead>
				<tbody>
				<c:forEach items="${page.rows}" var="row">
					<tr>
						<td>${row.order_id}</td>
						<td>${row.order_name}</td>
						<td>${row.order_cost}元</td>
						<td>${row.order_time}</td>
						<td>${row.order_uname}</td>
						<td>
							<c:if test="${row.order_state eq '0'}">
								订单未完成
							</c:if>
							<c:if test="${row.order_state ne '0'}">
								订单已完成
							</c:if>
						</td>
						<td>
							<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#customerEditDialog" onclick="editCustomer(${row.order_id})">查看详情</a>
							<a href="#" class="btn btn-danger btn-xs" onclick="deleteCustomer(${row.order_id})">删除</a>
						</td>
					</tr>
				</c:forEach>
				</tbody>
			</table>
			<div class="col-md-12 text-right">
				<ccut:page url="${pageContext.request.contextPath}/order/list" />
			</div>
			<!-- /.panel-body -->
		</div>
		<!-- /.panel -->
	</div>
	<!-- /.col-lg-12 -->
</div>
</div>
<!-- /#page-wrapper -->
</div>
<!-- 修改对话编辑框 -->
<div class="modal fade" id="customerEditDialog" tabindex="-1" role="dialog"
	 aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">订单详情</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_order_form">
					<input type="hidden" id="edit_order_id" name="order_id"/>
					<div class="form-group">
						<label for="edit_order_name" class="col-sm-2 control-label">订单名称</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_order_name" placeholder="订单名称" name="order_name">
						</div>
					</div>
					<div class="form-group">
						<label for="edit_order_cost" class="col-sm-2 control-label">订单金额</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_order_cost" placeholder="订单金额" name="order_cost">
						</div>
					</div>

					<div class="form-group">
						<label for="edit_order_time" class="col-sm-2 control-label">下单时间</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_order_time" placeholder="下单时间" name="order_time">
						</div>
					</div>
					<div class="form-group">
						<label for="edit_order_state" class="col-sm-2 control-label">订单状态</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_order_state" placeholder="订单状态" name="order_state">
						</div>
						</div>
					<div class="form-group">
						<label for="edit_order_uid" class="col-sm-2 control-label">下单人ID</label>
						<div class="col-sm-10">
						<input type="text" class="form-control" id="edit_order_uid" placeholder="下单人ID" name="order_uid">
						</div>
					</div>
					<div class="form-group">
						<label for="edit_product_id" class="col-sm-2 control-label">产品编码</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_product_id" placeholder="产品编码" name="product_id">
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
	<!-- jQuery -->
	<script src="${pageContext.request.contextPath}/mb/js/jquery.min.js"></script>

	<!-- Bootstrap Core JavaScript -->
	<script src="${pageContext.request.contextPath}/mb/js/bootstrap.min.js"></script>

	<!-- Metis Menu Plugin JavaScript -->
	<script src="${pageContext.request.contextPath}/mb/js/metisMenu.min.js"></script>

	<!-- DataTables JavaScript -->
	<script src="${pageContext.request.contextPath}/mb/js/jquery.dataTables.min.js"></script>
	<script src="${pageContext.request.contextPath}/mb/js/dataTables.bootstrap.min.js"></script>

	<!-- Custom Theme JavaScript -->
	<script src="${pageContext.request.contextPath}/mb/js/sb-admin-2.js"></script>

	<script type="text/javascript">
		function editCustomer(id) {
			$.ajax({
				type:"post",
				url:"${pageContext.request.contextPath}/order/edit",
				data:{"id":id},
				success:function(data) {
					$("#edit_order_id").val(data.order_id);
					$("#edit_order_name").val(data.order_name);
					$("#edit_order_cost").val(data.order_cost)
					$("#edit_order_time").val(data.order_time)
					if (data.order_state==0){
						$("#edit_order_state").val('未完成')
					}else{
						$("#edit_order_state").val('已完成')
					}
					$("#edit_order_uid").val(data.order_uid)
					$("#edit_product_id").val(data.product_id)

				}
			});
		}

		function deleteCustomer(id) {
			if(confirm('确实要删除该订单吗?')) {
				$.post("${pageContext.request.contextPath}/order/delete",{"id":id},function(data){
					if(data == "0"){
						alert("订单信息删除成功！");
					}else{
						alert("订单信息删除失败！");
					}
					window.location.reload();
				});
			}
		}
	</script>
</body>

</html>
